//
//  ViewController.m
//  Object-CPlayGround
//
//  Created by 韩丛旸 on 16/7/13.
//  Copyright © 2016年 韩丛旸. All rights reserved.
//


#import "ViewController.h"
#import "UIColor+HYExtension.h"
#import <WebKit/WebKit.h>
#import <objc/runtime.h>
#import "RuntimeMethod.h"
#import "Model.h"
#import "SectionModel.h"
#import <SWTableViewCell.h>

#define home_activity_tableName  @"home_activity_table"
#define home_activity_storeName  @"home_activity.db"
#define home_activity_JSONKey    @"home_activity_key"

#define  isEmptyNSString(string) (!([string isKindOfClass:[NSString class]] &&\
string != NULL &&\
string != nil &&\
![string isEqualToString:@""]))

#define dictionaryValue(dictionary, key) dictionary[key]?:@""
#define keyAndDictionaryValue(key, dictionary, dictionaryKey) key:dictionary[key]?:@""


#if DEBUG
#import "FLEXManager.h"
#endif

@interface ViewController ()<UITextViewDelegate>

@property (nonatomic, strong) NSSet *tempSet;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UIView *container;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIButton *editButton;


@end

@implementation ViewController


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    
    

    
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString *documentsDirectory = [paths objectAtIndex:0];
//    NSFileManager *fileManager = [NSFileManager defaultManager];
//    NSString *testDirectory = [documentsDirectory stringByAppendingPathComponent:@"test"];
//    // 创建目录
//    [fileManager createDirectoryAtPath:testDirectory withIntermediateDirectories:YES attributes:nil error:nil];
//
//    NSString *hyPath = [testDirectory stringByAppendingPathComponent:@"testhy"];
//    hyPath = [hyPath stringByAppendingPathExtension:@"txt"];
//    NSLog(@"%@", [hyPath pathExtension]);
//    NSString *testPath = hyPath;
////    NSString *testPath = [testDirectory stringByAppendingPathComponent:@"test00.txt"];
//    NSString *testPath2 = [testDirectory stringByAppendingPathComponent:@"test22.txt"];
//    NSString *testPath3 = [testDirectory stringByAppendingPathComponent:@"test33.txt"];
//
//
//    NSString *string = @"写入内容，write String";
//    [fileManager createFileAtPath:testPath contents:[string  dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
//    [fileManager createFileAtPath:testPath2 contents:[string  dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
//    [fileManager createFileAtPath:testPath3 contents:[string  dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
//
//
//    NSLog(@"%@", testDirectory);
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.delaysContentTouches = YES;
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self.view);
    }];
    
    self.container = [[UIView alloc] init];
    [self.scrollView addSubview:self.container];
    [self.container mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.scrollView);
        make.width.equalTo(self.scrollView);
    }];
    
    self.editButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.editButton setBackgroundColor:[UIColor redColor]];
    [self.container addSubview:self.editButton];
    [self.editButton addTarget:self action:@selector(click) forControlEvents:(UIControlEventTouchUpInside)];
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.container).mas_offset(100);
        make.left.mas_equalTo(self.container).mas_offset(100);
        make.right.mas_equalTo(self.container).mas_offset(-100);
        make.height.mas_equalTo([UIScreen mainScreen].bounds.size.height);
    }];
    
    [self.container mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.editButton.mas_bottom);
    }];

    
    
}

- (void)click {
    
    static BOOL isH = YES;
    
    if (isH) {
        
        [self.editButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.container).mas_offset(100);
            make.left.mas_equalTo(self.container).mas_offset(100);
            make.right.mas_equalTo(self.container).mas_offset(-100);
            make.height.mas_equalTo([UIScreen mainScreen].bounds.size.height * 3);
        }];
    }
    else {
        
        [self.editButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.container).mas_offset(100);
            make.left.mas_equalTo(self.container).mas_offset(100);
            make.right.mas_equalTo(self.container).mas_offset(-100);
            make.height.mas_equalTo([UIScreen mainScreen].bounds.size.height);
        }];
    }

    isH = !isH;
    
}

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
//
//    UILabel *label = [UILabel new];
//    label.text = @"ack中所包含的是ShaderlabVSCode的Free版本，这个插件不会每个方法与函数具体说明。如果您想有更丰富的解释来辅助你编写着色器";
//    [self.view addSubview:label];
//    label.numberOfLines = 0;
//    CGSize size = [label sizeThatFits:CGSizeMake(100, MAXFLOAT)];
//    [label mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.center.mas_equalTo(self.view);
//        make.width.mas_equalTo(size.width);
//        make.height.mas_equalTo(size.height);
//
//    }];
    
////    Model *model1 = [[Model alloc] init];
////    model1.module_name = @"测试d";
////    model1.plate_style = @"1";
////    model1.img_no = @"1";
////
////
////    Model *model2 = [[Model alloc] init];
////    model2.module_name = @"测试c";
////    model2.plate_style = @"1";
////    model2.img_no = @"1";
////
////
////    Model *model3 = [[Model alloc] init];
////    model3.module_name = @"测试c";
////    model3.plate_style = @"1";
////    model3.img_no = @"2";
////
////    Model *model4 = [[Model alloc] init];
////    model4.module_name = @"测试a";
////    model4.plate_style = @"1";
////    model4.img_no = @"1";
////
////    Model *model5 = [[Model alloc] init];
////    model5.module_name = @"测试c";
////    model5.plate_style = @"2";
////    model5.img_no = @"1";
////
////    Model *model6 = [[Model alloc] init];
////    model6.module_name = @"测试c";
////    model6.plate_style = @"1";
////    model6.img_no = @"4";
////
////    Model *model7 = [[Model alloc] init];
////    model7.module_name = @"测试c";
////    model7.plate_style = @"1";
////    model7.img_no = @"3";
////
////    Model *model8 = [[Model alloc] init];
////    model8.module_name = @"测试d";
////    model8.plate_style = @"1";
////    model8.img_no = @"2";
////
////    NSSet<Model *> *originalArr = [NSSet setWithArray:@[model1, model2, model3, model4, model5, model6, model7, model8]];
////
////    NSSortDescriptor *des1 = [NSSortDescriptor sortDescriptorWithKey:@"module_name" ascending:YES];
////    NSSortDescriptor *des2 = [NSSortDescriptor sortDescriptorWithKey:@"plate_style" ascending:YES];
////    NSSortDescriptor *des3 = [NSSortDescriptor sortDescriptorWithKey:@"img_no" ascending:YES];
////
////    NSArray<Model *> *arr = [originalArr sortedArrayUsingDescriptors:@[des1, des2, des3]];
////
////    NSMutableArray<NSNumber *> *keyPosition = @[@(0)].mutableCopy;
////
////    __block NSString *tempStr1 = arr[0].module_name;
////    __block NSString *tempStr2 = arr[0].plate_style;
////
////    [arr enumerateObjectsUsingBlock:^(Model * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
////
////        if ([tempStr1 isEqualToString:obj.module_name] == NO) {
////            [keyPosition addObject:@(idx)];
////            tempStr1 = obj.module_name;
////            tempStr2 = obj.plate_style;
////
////        } else if ([tempStr2 isEqualToString:obj.plate_style] == NO) {
////            NSLog(@"%ld", idx);
////            [keyPosition addObject:@(idx)];
////            tempStr1 = obj.module_name;
////            tempStr2 = obj.plate_style;
////        }
////
////    }];
////
////
////    NSMutableArray *resultArr = @[].mutableCopy;
////    [keyPosition enumerateObjectsUsingBlock:^(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
////        if (idx < keyPosition.count - 1) {
////            [resultArr addObject:[arr subarrayWithRange:NSMakeRange(obj.integerValue, keyPosition[idx + 1].integerValue - obj.integerValue)]];
////        } else {
////            [resultArr addObject:[arr subarrayWithRange:NSMakeRange(obj.integerValue, arr.count  - obj.integerValue)]];
////
////        }
////    }];
////
////
////    dispatch_queue_t concurrentQuene = dispatch_queue_create("concurrentQuene", DISPATCH_QUEUE_SERIAL);
////
////    dispatch_block_t block = dispatch_block_create(0, ^{
////        for (NSInteger i = 0; i < 100; i++) {
////            NSLog(@"+++++++++%@", [NSThread currentThread]);
////        }
////    });
////    dispatch_async(concurrentQuene, block);
////
////    //
////    dispatch_block_t qosBlock = dispatch_block_create_with_qos_class(0, QOS_CLASS_USER_INTERACTIVE, 0, ^{
////        for (NSInteger i = 0; i < 100; i++) {
////            NSLog(@"---------%@", [NSThread currentThread]);
////        }    });
////    dispatch_async(concurrentQuene, qosBlock);
//
//
//
//    NSBlockOperation * op2 = [[NSBlockOperation alloc] init];
//    [op2 addExecutionBlock:^{
//        for (NSInteger i = 0; i < 10; i++) {
//            NSLog(@"+++%@", [NSThread currentThread]);
//        }
////        sleep(10);
////        NSLog(@"op2.....handle..... on 10 hread num%@",[NSThread currentThread]);
//    }];
//
//    [op2 addExecutionBlock:^{
//        for (NSInteger i = 0; i < 10; i++) {
//            NSLog(@"---%@", [NSThread currentThread]);
//        }
////        sleep(6);
////        NSLog(@"op2.....handle..... on 6 thread num%@",[NSThread currentThread]);
//    }];
//
////    [op2 addExecutionBlock:^{
////        sleep(4);
////        NSLog(@"op2.....handle..... on 4 thread num%@",[NSThread currentThread]);
////    }];
////
////    [op2 addExecutionBlock:^{
////        sleep(8);
////        NSLog(@"op2.....handle..... on 8 thread num%@",[NSThread currentThread]);
////    }];
////
////    [op2 addExecutionBlock:^{
////        sleep(1);
////        NSLog(@"op2.....handle..... on 1 thread num%@",[NSThread currentThread]);
////    }];
////    [op2 setCompletionBlock:^{
////        NSLog(@"op2........OK !!");
////    }];
//    [op2 start];
//

    

    
    
    

    
}

@end
